## Import modules

# Windows 7 Resource Kit Powershell Pack
Import-Module TaskScheduler, WPK, FileSystem, DotNet, PSCodeGen, PSUserTools, PSSystemTools #, PSImageTools, PSRss

import-module josheinstein-scripting, josheinstein-dependency, josheinstein-linq, josheinstein-mapi, josheinstein-tempfiles
Initialize-TempLocation | Write-Verbose
sal %% progress-object

add-pssnapin pscx
"Cd", "Dir", "GenericFilters" |
    % { 
        . (join-path ${env:ProgramFiles(x86)} "PowerShell Community Extensions\Profile\$_.ps1") 
    }
# some PSCX aliases conflict with richardberg-misc
del 'Alias:\`?:' -Force -ea 0
del 'Alias:\`?`?' -Force -ea 0
del 'Alias:\gpv' -Force -ea 0

import-module -verbose leeholmes, module, powerboots, windbg #, SQLPSX
add-pssnapin -verbose poshhttp

import-module -verbose richardberg-misc
import-module -verbose richardberg-tivo, richardberg-tfs #, richardberg-test
Initialize-SqlProvider


## set some important state vars
# this file
set-variable mainProfile $myinvocation.mycommand.path -scope global

# env variables with () in them are extremely annoying - can't use $env:var syntax - so make a better copy
set-variable ProgramFilesX86 (?? {cat 'Env:\ProgramFiles(x86)' -ea SilentlyContinue} {$Env:ProgramFiles}) -scope global 

# mark WOW64 and Admin processes
set-variable UnderWOW $($env:PROCESSOR_ARCHITECTURE -ne $env:PROCESSOR_ARCHITEW6432)  -scope global 
set-variable IsAdmin $(Test-IsAdministrator) -scope global

## my custom prompt function
function prompt {
    # v2 default:
    # $(if (test-path variable:/PSDebugContext) { '[DBG]: ' } else { '' }) + 'PS ' + $(Get-Location) + $(if ($nestedpromptlevel -ge 1) { '>>' }) + '> '

    $dbg = $(if (test-path variable:/PSDebugContext) { '[DBG] ' })
    $admin = $(if ($IsAdmin) { '[Admin] '})
    $x86 = $(if ($UnderWOW) { '[x86] ' })
    $currentDir = $(Get-Location) | convertto-fullpath
    $prompt = $(if ($nestedpromptlevel -ge 1) { '>>' }) + '> '
    
    $Host.UI.RawUI.WindowTitle = $admin + $dbg + $x86 + $currentDir
    return $currentDir + $prompt
}

## shortcuts to commonly used directories
function main { cd c:\workspaces\main }
function prod { cd c:\workspaces\prod }
function sil { cd c:\workspaces\silverlight }
function ws2 { cd c:\workspaces\ws2 }
function rb { cd c:\users\rberg }
function mod { cd C:\users\rberg\Documents\WindowsPowerShell\Modules }
function pf { cd $env:ProgramFiles }
function pf2 { cd ${env:ProgramFiles(x86)} }

## other shortcuts
set-variable RandomVar $(new-object Random) -scope global
function random {
    $RandomVar.Next()
}
function backup {
    tf shelve /replace ("backup" + (random))
}